package com.zyy.seckill.controller;

import com.zyy.seckill.service.IUserService;
import com.zyy.seckill.vo.LoginVo;
import com.zyy.seckill.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * 登录
 * @Author: zyy
 * @DateTime: 2021/10/3 17:09
 */
@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {

    @Autowired
    private IUserService userService;

    /**
     * 跳转登录页面
     * @return
     */
    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }


    /**
     *  登录功能
     *
     * @param loginVo
     * @return
     */
    @RequestMapping("/doLogin")
    @ResponseBody
    public RespBean doLongin(@Valid LoginVo loginVo,
                             HttpServletRequest request,
                             HttpServletResponse response){

//        log.info("info: {}",loginVo);
        return userService.doLongin(loginVo,request,response);
    }
}
